#include "GTime.hpp"

#include "Exception.hpp"


namespace se {
///////////////////////////////////////////////////////////////////////////////
/// \brief The default constructor.
///////////////////////////////////////////////////////////////////////////////
System::GTime::GTime():
	m_clock(),
	m_lastUpdateTime(){
	Update();
}

///////////////////////////////////////////////////////////////////////////////
/// \brief Update the global time.
///
/// This member function update the global time.
/// Without it, the time stays constant.
/// It should be called after each loop.
/// @see Game_s()
/// @see Game_ms()
/// @see Game_fast()
///////////////////////////////////////////////////////////////////////////////
void System::GTime::Update() {
	m_lastUpdateTime = m_clock.getElapsedTime().asMicroseconds();
}

///////////////////////////////////////////////////////////////////////////////
/// \brief Gets the current time in fast mode.
///
/// The fast time is the current time (since program launch) directly outputed by clock().
/// You should divide it by get_tics_s() to get a number of seconds.
/// @see get_tics_s()
/// @see Game_s()
/// @see Game_ms()
/// @return current time in fast mode
///////////////////////////////////////////////////////////////////////////////
clock_t System::GTime::Game_fast() {
	return (clock_t)m_lastUpdateTime;
}

///////////////////////////////////////////////////////////////////////////////
/// \brief Gets the current time in milliseconds.
///
/// This is either the time outputed by clock, if the system clock is in milliseconds,
/// or calculated from it, that is slower, but it's the same (almost).
/// @see Game_s()
/// @see Game_fast()
/// @return current time in milliseconds
///////////////////////////////////////////////////////////////////////////////
Time_t System::GTime::Game_ms() {
	return m_lastUpdateTime/1000;
}

///////////////////////////////////////////////////////////////////////////////
/// \brief Gets the current time in seconds.
///
/// Gets a float being the number of seconds since program launch.
/// @see Game_ms()
/// @see Game_fast()
/// @return current time in seconds
///////////////////////////////////////////////////////////////////////////////
double System::GTime::Game_s() {
	return ((double)m_lastUpdateTime)*get_tics_s();
}

///////////////////////////////////////////////////////////////////////////////
/// \brief Gets the current system time.
///
/// returns a time in seconds since 1970, can be transformed with functions of ctime.
/// @return current system time
///////////////////////////////////////////////////////////////////////////////
time_t System() {
	return time(NULL);
}

///////////////////////////////////////////////////////////////////////////////
/// \brief The destructor.
///////////////////////////////////////////////////////////////////////////////
System::GTime::~GTime() {
	//nothing to do here
}

// just for the documentation
///////////////////////////////////////////////////////////////////////////////
/// @fn uint_fast32_t System::GTime::get_tics_s()
/// @return the number of tics per second
///////////////////////////////////////////////////////////////////////////////

}// </namespace se>
